package behavior;

import arena.Node;
import robot.Robot;

/**
 * Behavior is an abstract class that is extended by all of the other behaviors
 * to ensure that these behaviors are written properly and to provide an
 * abstract interface to behaviors by the client application.
 *
 * @author      Gabriel Loewen
 * @author      James Weston
 * @author      Jackie O'Quinn
 */

public abstract class Behavior {

    /**
     * The robot which is assigned to this behavior.  Note:  The behavior class
     * is instantiated for each robot individually.
     */
    protected Robot robot;

    /**
     * A unique name that describes each behavior
     */
    protected String behaviorID;

    /**
     * Default constructor
     */
    public Behavior(String id) {
        this.behaviorID = id;
    }

    /**
     * Constructor.  Takes a robot as a parameter and attaches this behavior to
     * that robot object.
     * @param   r   The robot which will be using this behavior
     */

    public void setRobot(Robot r) {
        this.robot = r;
    }

    /**
     * @return The name of the behavior.
     */
    public String getID() {
        return behaviorID;
    }


    /**
     * Checks whether a node exists within the grid
     * @param   goal     The node being checked in (x,y) format.
     * @return  Boolean value representing the existence of the node
     */
    public boolean nodeExists(String goal) {
        if (robot.getArena().nodeMap.containsKey(goal) &&
                robot.getArena().nodeMap.get(goal).getColor() != Node.DELETED &&
                !robot.getArena().nodeMap.get(goal).isOccupied) {
            return true;
        }

        return false;
    }

    /**
     * Returns the current progress of the behavior
     * @return The progress of the behavior
     */
    public abstract double getProgress();

    /**
     * Resets the behaviors progress
     */
    public abstract void resetProgress();

    /**
     * Generates a path for the robot to take from its current position to
     * the goal node.
     * @param   goal     The node being checked in (x,y) format.
     * @param   cancel   Boolean parameter to cancel the behaviors progress
     */
    public abstract void getPath(String goal, boolean cancel);

    /**
     * Returns whether a move exists
     * @return True if there is another move
     */
    public abstract boolean hasMove();

    /**
     * Returns the next move for the robot
     * @return A standard int array of values formatted to be read by the robot
     */
    public abstract int[] nextMove();

    /**
     * Returns whether a move is valid or not
     * @return True if the move is valid
     */
    public abstract boolean isValidMove();
}
